package com.yn.iotxiao.sql.services.Group;

import com.alibaba.fastjson.JSONObject;
import com.yn.iotxiao.Utils.JsonHelper;
import com.yn.iotxiao.sql.entity.Device.DeviceInfo;
import com.yn.iotxiao.sql.entity.Group.GroupDevice;
import com.yn.iotxiao.sql.entity.Group.GroupInfo;
import com.yn.iotxiao.sql.mapper.GroupMapper;
import com.yn.iotxiao.sql.services.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class GroupServiceImpl extends BaseServiceImpl<GroupInfo> implements GroupService {

    @Autowired
    GroupMapper gMapper;

    @Override
    public GroupInfo getWithType(String type) {
        return gMapper.getWithType(type);
    }

    @Override
    public int putDevice(List<GroupDevice> list) {
        return gMapper.putDevice(list);
    }

    @Override
    public List<DeviceInfo> getDeviceOutGroup(String groupId) {
        return gMapper.getDeviceOutGroup(groupId);
    }

    @Override
    public List<DeviceInfo> getGroupDevices(String groupId) {
        return gMapper.getGroupDevices(groupId);
    }

    @Override
    public List<DeviceInfo> getDeviceInGroup(String groupId, String searchKey, int page, int pageSize) {
        return gMapper.getDeviceInGroup(groupId,searchKey,page,pageSize);
    }

    @Override
    public int getDeviceInGroupTotal(String groupId) {
        return gMapper.getDeviceInGroupTotal(groupId);
    }

    @Override
    public int removeDeviceFromGroup(String groupId, List<String> deviceIds) {
        return gMapper.removeDeviceFromGroup(groupId,deviceIds);
    }

    @Override
    public int putUser(String uid, String type,String groupId,String deviceIds) {
        return gMapper.putUser(uid,type,groupId, deviceIds);
    }

    @Override
    public JSONObject getUserInGroup(String groupId, String searchKey, int page, int pageSize) {
        var list = gMapper.getUserInGroup(groupId,searchKey,page,pageSize);
        var total = gMapper.getUserInGroupTotal(groupId,searchKey);
        return JsonHelper.create("total",total,"list",list);
    }
}
